package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.TransactionRecord;
import cn.wolfcode.trip.base.mapper.TransactionRecordMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.TransactionRecordQuery;
import cn.wolfcode.trip.base.service.ITransactionRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TransactionRecordServiceImpl implements ITransactionRecordService {

    @Autowired
    private TransactionRecordMapper transactionRecordMapper;

    @Override
    public PageInfo query(QueryObject queryObject) {
        PageHelper.startPage(queryObject.getCurrentPage(),queryObject.getPageSize(),queryObject.getOrderBy());
        List<TransactionRecord> transactionRecords = transactionRecordMapper.selectForList(queryObject);
        return new PageInfo(transactionRecords);
    }

    @Override
    public void delete(Long id) {
        transactionRecordMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void save(TransactionRecord transactionRecord) {
        transactionRecordMapper.insert(transactionRecord);
    }

    /**
     * 前台查询商品交易记录
     * @param qo
     * @return
     */
    @Override
    public PageInfo queryForApp(TransactionRecordQuery qo){
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<TransactionRecord> transactionRecords = transactionRecordMapper.selectForApp(qo);
        return new PageInfo(transactionRecords);
    }

}
